
<!DOCTYPE html>
<html>
<head>
  <title>登入</title>
   <#include "../common/link.ftl">
</head>
<body>

<#include "../common/header.ftl">

<div class="layui-container fly-marginTop">
  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title">
        <li class="layui-this">登入</li>
        <li><a href="${ctx.contextPath}/user/reg">注册</a></li>
      </ul>
      <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">
          <div class="layui-form layui-form-pane">
            <#--<form method="post">-->
              <div class="layui-form-item">
                <label for="email" class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                  <input type="text" id="email" name="email" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="pass" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="pass" name="pass" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="authcode" class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                  <input type="text" id="authcode" name="authcode" required lay-verify="required" autocomplete="off" placeholder="请回答后面的问题" class="layui-input">
                </div>
                <div>
                    <img class="pointer" id="code_img" src="${ctx.contextPath}/authcode/calculate" alt="点击刷新"/>
                </div>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn" id="login_btn">立即登录</button>
                <span style="padding-left:20px;">
                  <a href="${ctx.contextPath}/user/forget">忘记密码？</a>
                </span>
              </div>
            <#--</form>-->
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<#include "../common/footer.ftl">

<script>
layui.cache.page = 'user';
layui.cache.user = {
  username: '游客'
  ,uid: -1
  ,avatar: '${ctx.contextPath}/static/images/avatar/00.jpg'
  ,experience: 83
  ,sex: '男'
};
layui.config({
  version: "3.0.0"
  ,base: '${ctx.contextPath}/static/mods/'
}).extend({
  fly: 'index'
}).use(['fly','form'], function () {
    var $ = layui.$;

    //刷新验证码
    $("#code_img").on("click", function () {
        $(this).attr("src" ,  "${ctx.contextPath}/authcode/calculate?t=" + $.now());
    });

    //登录
    $("#login_btn").on("click", function () {
        var email_dom = $("#email"), password_dom = $("#pass"), authcode_dom = $("#authcode");
        if (!mq.verify_email(email_dom) || !mq.verify_val(password_dom) || !mq.verify_val(authcode_dom)) {
            return false;
        }
        var email = email_dom.val(), password = password_dom.val(),authcode = authcode_dom.val();
        var ctx = "${ctx.contextPath}";//项目根路径
        //发送异步请求
        var data = {email:email, password:password, authcode:authcode};
        mq.async(ctx + "/user/loginHandle", data, ctx);
        setTimeout(function () {
            $("#code_img").click();
        }, 200);
    });

    //监听按下回车键
    $("body").keydown(function() {
        if (event.keyCode == "13") {
            $("#login_btn").click();
        };
    });

});
</script>

</body>
</html>